#ATM机的存取款功能
#ATM角色 50000
#用户角色 5000
#1、先登录
#   根据用户登录
#2、菜单界面
#   1、取款
#      用户的账户金额就减少了500
#   2、存款
#      用户的账户金额就增加了500块
#   3、查询
#      用户的账户金额显示

atm = 50000
user_dict = {"root":{"passwd":"123456","balance":5000},"suda":{"passwd":"499499","balance":10000}}

def login(username,passwd):
    if username in user_dict and passwd == user_dict[username]["passwd"]:
        return True

def get_money(money,user):
    global atm
    if money <= user_dict[user]["balance"] and money <= atm:
        atm -= money
        user_dict[user]["balance"] -= money
    else:
        print("你的余额不足")

def save_money(money,user):
    global atm
    atm += money
    user_dict[user]["balance"] += money

user = input("请输入用户名:")
passwd = input("请输入密码:")
# 先要登录成功，才能够返回出来菜单
if login(user, passwd):# 返回值为True
    print("Welcome to sanchuang atm!")
    while True:
        print("1、取款\n2、存款\n3、查询\n4、退出")
        choose = input("请输入你的选择:")
        if choose == "1":
            money = int(input("请输入你的取款金额:"))
            get_money(money,user)
        elif choose == "2":
            money = int(input("请输入你的存款金额:"))
            save_money(money,user)
        elif choose == "3":
            print(f'你的卡内余额为{user_dict[user]["balance"]}')
        elif choose == "4":
            print("Thank you for using sanchuang atm!")
            break
elif user in user_dict:
    print("密码输入错误")
else:
    print("用户名输入错误")
